<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        .box ,.demo {
            width: 200px;
            height: 100px;
            background-color: #ccc;
            font-size: 20px;
            text-align: center;
            line-height: 100px;
            margin: 50px auto 0;
            position: fixed;
            left: 200px;
        }

        .box {
            top: 50px;
        }
        .demo {
            top: 200px;
        }
    </style>
</head>
<body style="height: 2000px;">
    <div class="box"> 防抖:0 </div>
    <div class="demo"> 节流:0 </div>


    <script src="./封装函数/debounce.js"></script>
    <script src="./封装函数/trottle.js"></script>
    <script>
       // 获取相关的标签
       var box = document.querySelector(".box");
       var demo = document.querySelector(".demo");

       // 计数器变量
       var count = 0;
       var num = 0;

       // 绑定事件 (滚动事件)
       //var _type = "scroll";
       var _type = "resize";
       // 防抖
       window.addEventListener(_type,debounce(function(){
            count ++;
            box.innerHTML ="防抖:"+count;
       },300))

       // 节流
       window.addEventListener(_type,trottle(function(){
            num ++;
            demo.innerHTML ="节流:"+num;
      },300))
       


    </script>
</body>
</html>